package com.lvmama.rhino.collector.utils

import org.xerial.snappy.Snappy

/**
  * Created by yuanxiaofeng on 2016/3/17.
  */
object SnappyUtils {
  /**
    * 输入字符集
    */
  private val INPUT_CHARSET: String = "UTF-8"

  /**
    * 字符串压缩
    * @param str  待压缩字符串
    * @return  返回byte数组
    */
  def compress(str: String): Array[Byte] ={
    val compressed = Snappy.compress(str.getBytes(INPUT_CHARSET))
    compressed
  }

  /**
    * byte数组解压
    * @param bytes 待解压byte数组
    * @return 返回解压后字符串
    */
  def uncompress(bytes: Array[Byte]): String ={
    val uncompressed = Snappy.uncompress(bytes)
    val result = new String(uncompressed, INPUT_CHARSET)
    result
  }
}
